package com.lyf.scm.plan.domain.remote.nateWork.facade;

import com.alibaba.fastjson.JSON;
import com.lyf.scm.common.enums.ResponseMsg;
import com.lyf.scm.plan.domain.remote.nateWork.NateWorkRemote;
import com.lyf.scm.plan.domain.remote.nateWork.dto.SalesNetworkAnalysisDTO;
import com.lyf.scm.plan.domain.remote.nateWork.dto.SearchSourceToBReturnDTO;
import com.lyf.scm.plan.domain.remote.nateWork.dto.SearchSourceToCQueryDTO;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 *
 * @author: haodong
 * @data: 2020/10/7 16:55
 */
@Slf4j
@Service
public class NateWorkFacade {

    @Resource
    private NateWorkRemote nateWorkRemote;

    /**
     * TOB寻仓
     * @param storeCodeList
     * @return
     */
    public List<SearchSourceToBReturnDTO> searchToBSource(List<String> storeCodeList){
        log.info("TOB寻仓入参:storeCodeList:{}", JSON.toJSONString(storeCodeList));
        Response<List<SearchSourceToBReturnDTO>> response = nateWorkRemote.searchToBSource(storeCodeList);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2009.getCode(),ResponseMsg.EXCEPTION_2009.getMsg());
        }
        return response.getData();
    }

    /**
     * TOC寻仓
     * @param queryToCList
     * @return
     */
    public List<SearchSourceToCQueryDTO> searchToCSource(List<SearchSourceToCQueryDTO> queryToCList) {
        log.info("TOC寻仓入参:queryToCList:{}", JSON.toJSONString(queryToCList));
        Response<List<SearchSourceToCQueryDTO>> response = nateWorkRemote.searchToCSource(queryToCList);
        log.info("调组网寻仓返回数据:{}", response);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2009.getCode(),ResponseMsg.EXCEPTION_2009.getMsg());
        }
        return response.getData();
    }

    /**
     * 批量根据仓库编码查询渠道加区域信息
     * @param warehouseList
     * @return
     */
    public List<SalesNetworkAnalysisDTO> queryOutBoundByWarehous(List<String> warehouseList) {
        log.info("批量根据仓库编码查询渠道加区域信息入参:queryToCList:{}", JSON.toJSONString(warehouseList));
        Response<List<SalesNetworkAnalysisDTO>> response = nateWorkRemote.queryOutBoundByWarehous(warehouseList);
        log.info("批量根据仓库编码查询渠道加区域信息返回数据:{}", response);
        if(!ResponseMsg.SUCCESS.getCode().equals(response.getCode())){
            throw new RomeException(ResponseMsg.EXCEPTION_2009.getCode(),ResponseMsg.EXCEPTION_2009.getMsg());
        }
        return response.getData();
    }
}
